Skip to content

fix(bump.py): CHANGELOG.md gets git added and commited correctly #581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

lovetheguitar
Copy link
Contributor

@lovetheguitar lovetheguitar commented Sep 12, 2022

Description

The elements in version_files may contain not only a file path, but also a regex after a colon. Thus make sure to only pass the file path to
git add.

Fixes a regression introduced in 12b56ad.

Checklist

  • Add test cases to all the changes you introduce
  • Run ./scripts/format and ./scripts/test locally to ensure this change passes linter check and test
  • Test the changes on the local machine manually
  • Update the documentation for the changes

Expected behavior

CHANGELOG.md gets git added and commited no matter what version files (+ regex) one specifies.

Before and After

Before the following, broken, command was executed:
git add CHANGELOG.md pyproject.toml:^version src/my_package/__init__.py:^__version__

With this MR, the command looks like this:
git add CHANGELOG.md pyproject.toml src/my_package/__init__.py

Steps to Test This Pull Request

Have the following commitizen settings in pyproject.toml file:

[tool.commitizen]
version = "1.0.2"
version_files = [
    "pyproject.toml:^version",  # use regex to only update version at start of line (https://github.com/commitizen-tools/commitizen/issues/496)
    "src/my_package/__init__.py:^__version__",
]
tag_format = "v$major.$minor.$patch$prerelease"

In the git repo of my_package make sure there is no CHANGELOG.md file tracked by git yet.
Running cz bump will update the version correctly and also write the changelog file, but fail to git add it.

Additional context

@codecov
Copy link

codecov bot commented Sep 12, 2022

Codecov Report

Base: 98.25% // Head: 98.38% // Increases project coverage by +0.13% 🎉

Coverage data is based on head (f6ab845) compared to base (a199393).
Patch coverage: 95.45% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #581      +/-   ##
==========================================
+ Coverage   98.25%   98.38%   +0.13%     
==========================================
  Files          39       39              
  Lines        1605     1614       +9     
==========================================
+ Hits         1577     1588      +11     
+ Misses         28       26       -2     
Flag Coverage Δ
unittests 98.38% <95.45%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
commitizen/cli.py 93.93% <ø> (+1.51%) ⬆️
commitizen/git.py 98.59% <80.00%> (-0.67%) ⬇️
commitizen/__version__.py 100.00% <100.00%> (ø)
commitizen/bump.py 100.00% <100.00%> (ø)
commitizen/commands/bump.py 96.61% <100.00%> (+0.02%) ⬆️
commitizen/cz/base.py 100.00% <0.00%> (ø)
commitizen/changelog.py 100.00% <0.00%> (+1.13%) ⬆️
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Member

@Lee-W Lee-W left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @lovetheguitar ! This is awesome! Could we please add a few test case for it? Thanks!

@lovetheguitar
Copy link
Contributor Author

Found a few more bugs while writing tests, but sadly do not have time to fix them. Just gonna list them here for now:

  • In dry run mode, when running cz bump --dry-run --yes --check-consistency no inconsistency are checked/found at all.
  • Without dry run mode, when running cz bump --yes --check-consistency:
    • if there are inconsistencies found, a warning is printed, but the version in e.g. pyproject.tomls [tool.commitizen] section gets still incremented.
    • inconsistencies between pyproject.tomls [tool.commitizen] version and [tool.poetry]s version are not detected at all.

The elements in `version_files` may contain not only a file path, but
also a regex after a colon. Thus make sure to only pass the file path to
 `git add`. Closes commitizen-tools#581.
@lovetheguitar lovetheguitar force-pushed the fix/regression_since_v2.27.0_untracked_changelog_gets_git_added branch from 4d1205c to 4af68a0 Compare September 15, 2022 21:52
@lovetheguitar lovetheguitar force-pushed the fix/regression_since_v2.27.0_untracked_changelog_gets_git_added branch from 4af68a0 to f6ab845 Compare September 15, 2022 21:58
@woile woile merged commit 8c20258 into commitizen-tools:master Sep 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants